package com.ruoyi.iot.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.iot.domain.PioltDevice;
import com.ruoyi.iot.domain.PioltDeviceDyData;
import com.ruoyi.iot.service.DataMetaDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 观测站设备Controller
 *
 * @author rww
 * @date 2023-09-18
 */
@RestController
@RequestMapping("/iot/device/data")
public class PioltDeviceDataController extends BaseController
{
    @Autowired
    private DataMetaDbService dataMetaDbService;

    /**
     * 查询观测站设备列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PioltDeviceDyData pioltDevice)
    {
        startPage();
        List<PioltDeviceDyData> list = dataMetaDbService.
                selectPioltDeviceDataList(pioltDevice);
        return getDataTable(list);
    }

    /**
     * 导出观测站设备列表
     */
    @Log(title = "观测站设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PioltDeviceDyData pioltDevice)
    {
        List<PioltDeviceDyData> list = dataMetaDbService.selectPioltDeviceDataList(pioltDevice);
        ExcelUtil<PioltDeviceDyData> util = new ExcelUtil<PioltDeviceDyData>(PioltDeviceDyData.class);
        util.exportExcel(response, list, "观测站设备数据");
    }
}
